// import Vuex from 'vuex'
// import tab from './tab'

// export default new Vuex.Store({
//   modules: {
//     tab
//   }
// })
import { createStore } from 'vuex'

export default createStore({
  state: {
    token: localStorage.getItem('token'),
    id: localStorage.getItem('id'),
    userName: localStorage.getItem('userName'),
    role: localStorage.getItem('role'),
    nickname: localStorage.getItem('nickname'),
    avatar: localStorage.getItem('avatar'),
    email: localStorage.getItem('email'),
    password: localStorage.getItem('password'),
    tokenError: false,
    pageChanged: false,
  },
  getters: {
    
  },
  mutations: {
    pageChanged (state) {
      state.pageChanged = true
    },
    pageChangedComplete (state) {
      state.pageChanged = false
    },
    tokenError (state) {
      state.tokenError = true
    },
    tokenErrorComplete (state) {
      state.tokenError = false
    },
    setToken (state, data) {
      state.token = data
      localStorage.setItem('token', data)
    },
    setId (state, data) {
      state.id = data
      localStorage.setItem('id', data)
    },
    setUserName (state, data) {
      state.userName = data
      localStorage.setItem('userName', data)
    },
    setRole (state, data) {
      state.role = data
      localStorage.setItem('role', data)
    },
    setNickname (state, data) {
      state.nickname = data
      localStorage.setItem('nickname', data)
    },
    setAvatar (state, data) {
      state.avatar = data
      localStorage.setItem('avatar', data)
    },
    setEmail (state, data) {
      state.email = data
      localStorage.setItem('email', data)
    },
    setUser (state, data) {
      state.email = data.email
      localStorage.setItem('email', data.email)
      state.avatar = data.avatar
      localStorage.setItem('avatar', data.avatar)
      state.nickname = data.nickname
      localStorage.setItem('nickname', data.nickname)
      state.role = data.role
      localStorage.setItem('role', data.role)
      state.userName = data.userName
      localStorage.setItem('userName', data.userName)
      state.id = data.id
      localStorage.setItem('id', data.id)
      state.token = data.token
      localStorage.setItem('token', data.token)
      state.password = data.password
      localStorage.setItem('password', data.password)
    },
    logout (state) {
      localStorage.clear()
      state.email = null
      state.avatar = null
      state.nickname = null
      state.role = null
      state.userName = null
      state.id = null
      state.token = null
    },
  },
  actions: {
    
  },
  modules: {
  }
})
